﻿using Common.Contract;
using Common.Contract.Customer.Identifier;
using Common.Contract.Customer.Record;
using Common.Contract.DataCenter.Record;
using Common.Contract.DataCenter.Request;
using Common.Service.Command;
using Common.Service.Queue;
using Common.Util;
using DataCenter.Configuration;
using DataCenter.Model.Interface;
using DataCenter.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataCenter.ServiceCommand
{
    public class UpdateShopCellServiceCommand : ProviderQueueCommand<IProviderFactory, ShopCellRecord, ResponseRecord>
    {
        public UpdateShopCellServiceCommand(IProviderFactory provider) : base(provider) { }

        protected override void Validate(ShopCellRecord record)
        {
            if (record == null) throw new ArgumentNullException("request");
        }

        protected override bool OnExecute(ResponseRecord response)
        {
            var shop = Record;
            var obj = new ShopCell
            {
                ShopId = shop.ShopCode,
                CellNo = shop.ShopCell,
                //CreateDate = shop.CreateDate,
                ModifyDate = DateTime.Now,
                SoTransferFlag = BooleanString.TRUE,
                SoTransferDate = DateTime.Now,
                CreateUser = CONST_NAME.SYNCHRONIZE_ACCOUNT,
                ModifyUser = CONST_NAME.SYNCHRONIZE_ACCOUNT,
                UseFlag = shop.Active.ToBooleanString(),
            };
            var itemCheck = Providers.ShopCell.RetrieveShopCell(Record.ShopCode, Record.ShopCell);
            if (itemCheck == null)
            {
                var resultitem1 = Providers.ShopCell.Add(obj);
            }
            else
            {
                var resultitem2 = Providers.ShopCell.Update(obj);
            }
            return true;
        }
    }
}
